package com.alibaba.yinan.domain.resource.domain;

import lombok.Getter;

/**
 * @ClassName ContainerSlot
 * @Author mengke
 * @create 2025/8/17 16:12
 * @Description 容器槽位
 */

@Getter
public class ContainerSlot {

    /**
     * 槽位编号
     */
    private final String code;

    /**
     * 槽位是否被占用
     */
    private boolean occupied = false;

    /**
     * 槽位被占用的taskId
     */
    private String taskId;

    public ContainerSlot(String code) {
        this.code = code;
    }

    public boolean isFree() {
        return !occupied;
    }

    public void allocate(String taskId) {
        if (occupied) throw new IllegalStateException("Slot already occupied");
        this.taskId = taskId;
        this.occupied = true;
    }

    public void release() {
        this.taskId = null;
        this.occupied = false;
    }

}
